package com.blockmeta.bbs.overallserviceapplication.search.adapter;

import android.content.Context;
import androidx.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.blockmeta.bbs.baselibrary.base.adapter.BaseAdapter;
import com.blockmeta.bbs.baselibrary.utils.FormatUtil;
import com.blockmeta.bbs.baselibrary.utils.SharedPreferenceUtil;
import com.blockmeta.bbs.businesslibrary.arouter.RouterHelper;
import com.blockmeta.bbs.businesslibrary.arouter.RouterPath;
import com.blockmeta.bbs.businesslibrary.constant.Constant;
import com.blockmeta.bbs.businesslibrary.pojo.HomeMarketItemPOJO;
import com.blockmeta.bbs.overallserviceapplication.R;
import com.chad.library.adapter.base.BaseViewHolder;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by author on 2018/5/15.
 */

public class HomeMarketAdapter extends BaseAdapter<HomeMarketItemPOJO, BaseViewHolder> {
    private Context mContext;

    public HomeMarketAdapter(int layoutResId, @Nullable List<HomeMarketItemPOJO> data, Context context) {
        super(layoutResId, data);
        mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, final HomeMarketItemPOJO item) {
        if (!TextUtils.isEmpty(item.getLogo())) {
            Picasso.with(mContext).load(item.getLogo()).into((ImageView) helper.getView(R.id.market_logo));
        }
        helper.setText(R.id.market_name, item.getExchange());
        helper.setText(R.id.market_country, item.getLocation());
        double volumn = FormatUtil.parseDouble(item.getVolume()) * SharedPreferenceUtil.getFloat(mContext, Constant.CNY_USD, 6.4f);
        helper.setText(R.id.market_volumn, "24H量 ¥ " +
                                                   FormatUtil.longToVolumeHumanReadableFormat((long) volumn, 2));
        helper.setText(R.id.market_pair, "交易对 " + item.getPairs());
        helper.setText(R.id.market_index, "No." + item.getIndex());

        TextView tag1= helper.getView(R.id.market_tags1);
        TextView tag2= helper.getView(R.id.market_tags2);
        TextView tag3= helper.getView(R.id.market_tags3);
        if (!TextUtils.isEmpty(item.getTags())){
            if (item.getTags().contains("期货")){
                tag1.setVisibility(View.VISIBLE);
            }else {
                tag1.setVisibility(View.GONE);
            }
            if (item.getTags().contains("现货")){
                tag2.setVisibility(View.VISIBLE);
            }else {
                tag2.setVisibility(View.GONE);
            }
            if (item.getTags().contains("法币")){
                tag3.setVisibility(View.VISIBLE);
            }else {
                tag3.setVisibility(View.GONE);
            }
        }else {
            tag1.setVisibility(View.GONE);
            tag2.setVisibility(View.GONE);
            tag3.setVisibility(View.GONE);
        }



        View container = helper.getView(R.id.plate_main);
        container.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RouterHelper.startActivity(mContext, RouterPath.EXCHANGE_F10_ACTIVITY,item.getExchange(),item.getExchangeKey());
            }
        });

    }
}
